<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ include file="/WEB-INF/views/include/head.jsp"%>
<head>
<title>图片管理</title>
<link href="${ctxStatic}/upload/upload.css" type="text/css" rel="stylesheet" />
</head>
<script language=javascript>
	
	var s = '<c:out value="${success}" />'
	var filecount=1;
	if(s == 2){
		var flag = '<c:out value="${flag}" />'	
		uploadErr(flag);
	}
	else if(s == 1){
		msg = "";
		var c_pname = '<c:out value="${c_pname}" />';
		var a = '<c:out value="${a}" />';
		var spath = '<c:out value="${spath}" />';
		uploadOK(a,spath,c_pname);
	}
	
 	function uplfile(){
 	//	window.parent.document.getElementById('button').value = "1111";
 	//	window.parent.document.getElementById('AAAA').value = "bbb"; 
 		//window.parent.say();
 		//return ;
 		
 		var picge=false;
 		var filetype=document.uploadform.file1.value;
 		var array=filetype.split(".");
 		var typepic = array[array.length-1];
 		var info=document.getElementById("info");
 		var   allpict   =   ["pdf"];   
		for(f=0;f<allpict.length;f++){
			if(allpict[f]==typepic){
				picge=true;
			}
		 }
 		if(picge){
 			document.uploadform.submit();
 		}else{
 			msg="上传图片类型不正确!";
		info.innerHTML=msg;
		info.style.color='#FF0000';
 		}
 	}

//上传成功回调
function uploadOK(p,pic,picname)
{
	var menthodName = p + 'say';
	var s = "window.parent.parent."+menthodName+"('"+pic+"')";
	eval(s);
}

//上传失败回调
function uploadErr(errid)
{
	alert(errid);
	var msg = "图片上传失败,请重新上传!";
	switch(errid){
	  	case "1":
	  		msg = "图片格式不对,请从新上传!";
			break;
	  	case "2":
	  		msg = "图片容量超过300k,请从新上传!";
	  		break;
		
	}
	//alert(errid+msg);
	$(window.parent.document).find("#info").empty();
	$(window.parent.document).find("#info").html("<font color=red>"+msg+"</font>");
}

</script>

<body class="body">
	<div id="upload">
		<form action="${ctx}/shop/file/upload" method="post" name="uploadform"
			enctype="multipart/form-data" target="upfm">
			<input id="a" name="a" type="hidden" value="${a}"/>
			<table width="400" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td align="center">
						<div id=files>
							<input id="file1" type="file" name="file1" size="30" />
							<!--onchange=" checkfile();"-->
						</div>
					</td>
				</tr>
				<tr>
					<td height="30" align="center">
						<span id="info"></span>
					</td>
				</tr>
				<tr>
					<td height="30" align="center">
						<input type="button" value="开始上传" name="mybutton"
							onClick="uplfile()" id="btn" />
					</td>
				</tr>
				<tr>
					<td height="25" align="center"></td>
				</tr>
				<tr>
					<td height="10" align="center" valign="bottom">
						<font color="#999999">图片大小小于300k,建议使用.jpg .gif</font>
					</td>
				</tr>
			</table>

		</form>
	</div>
	<iframe id="upfm" name="upfm" style="display: none;"></iframe>
</body>
</html>
